package com.csun.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csun.dao.BaseDao;
import com.csun.entity.PageBean;
import com.csun.entity.Role;
import com.csun.entity.RoleRole;
import com.csun.service.RoleRoleService;

/**
 * @ClassName: RoleRoleServiceImpl.java
 * @Description:TODO
 * @author danjinsong danjingsong@dragonwake.cn
 * @date 2017年2月17日下午7:58:10
 * 
 */
@Service("roleRoleService")
public class RoleRoleServiceImpl implements RoleRoleService{
	
	@Autowired
	private BaseDao<RoleRole> roleRoleDao;
	
	@Autowired
	private BaseDao<Role> roleDao;
	
	
	@Override
	public void save(RoleRole roleRole) {
		roleRoleDao.saveOrUpdate(roleRole);
	}

	@Override
	public void delete(RoleRole roleRole) {
		roleRoleDao.delete(roleRole);
	}

	@Override
	public void delete(Integer id) {
		RoleRole roleRole = new RoleRole();
		roleRole.setId(id);
		roleRoleDao.delete(roleRole);
	}

	@Override
	public RoleRole get(RoleRole s_roleRole) {
		StringBuffer hql = new StringBuffer("from RoleRole r ");
		return roleRoleDao.get(hql.toString().replaceFirst(" and ", " where "),new Object[]{});
	}

	@Override
	public List<RoleRole> find(RoleRole s_roleRole, PageBean pagebean) {
		StringBuffer hql = new StringBuffer("from RoleRole r ");
		if(pagebean != null)
			return roleRoleDao.find(hql.toString().replaceFirst(" and ", " where "),new Object[]{},pagebean);
		return roleRoleDao.find(hql.toString().replaceFirst(" and ", " where "),new Object[]{});
	}


	@Override
	public Long count(RoleRole s_RoleRole) {
		StringBuffer hql = new StringBuffer("select count(*) as total from RoleRole r ");
		return roleRoleDao.count(hql.toString().replaceFirst(" and ", " where "),new Object[]{});
	}

}
